/**
 * Copyright 2009 Dan Hansen <hansen.danr@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.php.mojo.phar;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.File;

import org.apache.maven.plugin.MojoExecutionException;

/**
 * Build a PHAR of the test classes for the current project.
 * 
 * @author <a href="hansen.danr@gmail.com">Dan Hansen</a>
 * @version $Id: TestPharMojo.java 79 2009-07-27 03:47:52Z hansen.danr $
 * @goal test-phar
 * @phase package
 * @requiresProject
 * @requiresDependencyResolution test
 */
public class TestPharMojo
	extends AbstractPharMojo
{

	/**
	 * Set this to <code>true</code> to bypass unit tests entirely. Its use is
	 * <b>NOT RECOMMENDED</b>, but quite convenient on occasion.
	 * 
	 * @parameter expression="${maven.test.skip}"
	 */
	private boolean skip;

	/**
	 * Directory containing the test classes.
	 * 
	 * @parameter expression="${project.build.testOutputDirectory}"
	 * @required
	 */
	private File testClassesDirectory;

	/**
	 * Returns the artifact classifier.
	 * 
	 * @return String
	 * @see com.googlecode.php.mojo.phar.AbstractPharMojo#getClassifier()
	 */
	@Override
	protected String getClassifier()
	{
		return "tests";
	}

	/**
	 * Returns the type of the artifact.
	 * 
	 * @return type of the generated artifact
	 */
	@Override
	protected String getType()
	{
		return "test-phar";
	}

	/**
	 * Return the test-classes directory, to serve as the root of the tests
	 * phar.
	 */
	@Override
	protected File getClassesDirectory()
	{
		return testClassesDirectory;
	}

	/**
	 * Executions the test-phar plugin goal.
	 * 
	 * @see com.googlecode.php.mojo.phar.AbstractPharMojo#execute()
	 */
	@Override
	public void execute() throws MojoExecutionException
	{
		if ( skip )
		{
			getLog().info( "Skipping packaging of the test-phar" );
		}
		else
		{
			super.execute();
		}
	}
}
